package com.xyy.saas.payment.manage.cores.enums;

import java.util.Arrays;
import java.util.Map;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;

public enum BusinessOrderTypeEnum {
    /**
     * 一块钱医生业务类型
     */
    YIKUAIQIAN_DOC("yikuaiqian_doc", "一块钱医生"),
    /**
     * 一块钱富民业务类型
     */
    YIKUAIQIAN_FM("yikuaiqian_fm", "一块钱富民"),
    /**
     * 一块钱药店业务类型
     */
    YIKUAIQIAN_DRUGSTORE("yikuaiqian_drugstore", "一块钱药店"),
    /**
     * ec_ka
     */
    EC_KA("ec_ka", "ec_ka"),
    /**
     * ec_order
     */
    EC_ORDER("ec_order", "ec_order"),
    /**
     * 毛竹
     */
    SAAS_CRM("saas_crm", "毛竹"),

    /**
     * 单品交易
     */
    SAAS_TRADE("saas_trade", "单品交易"),

    /**
     * 宜块钱资质认证业务
     */
    YIKUAIQIAN_ATTESTATION("yikuaiqian_attestation", "宜块钱资质认证业务"),
    /**
     * 宜块钱保险业务
     */
    YIKUAIQIAN_INSURANCE("yikuaiqian_insurance", "宜块钱保险业务"),
    /**
     * 宜块钱保险业务
     */
    YIKUAIQIAN_LINGZHI("yikuaiqian_lingzhi", "宜块钱保险业务"),
    /**
     * 智慧脸商城
     */
    SAAS_MALL("saas_mall", "智慧脸商城"),
    /**
     * 药帮忙POP
     */
    EC_POP("ec_pop", "药帮忙POP");

    private static Map<String,BusinessOrderTypeEnum> code2Enum;

    static {
        code2Enum = Arrays.asList(values()).stream().collect(Collectors.toMap(BusinessOrderTypeEnum::getType, UnaryOperator.identity()));
    }

    public static BusinessOrderTypeEnum getEnum(String type){
        return code2Enum.get(type);
    }


    public static String getBusinessType(BusinessOrderTypeEnum businessOrderType) {
        switch(businessOrderType) {
            case EC_POP:
                return BusinessTypeEnum.EC.getType();
        }

        throw new UnsupportedOperationException("UnsupportedOperationException#getBusinessType, businessOrderType=" + businessOrderType);
    }

    private String type;
    private String desc;

    BusinessOrderTypeEnum(String type, String desc){
        this.type = type;
        this.desc = desc;
    }

    public String getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    public static boolean contains(String type) {
        try {
           return BusinessOrderTypeEnum.valueOf(type.toUpperCase()).type.equals(type);
        } catch (Exception e) {
        }
        return false;
    }
}
